package com.team.databoard.util;

import com.team.databoard.constant.StudentConstant.*;
import com.team.databoard.model.Student;

import java.sql.Date;
import java.time.LocalDate;

public class VerifyUtils {
    /**
     * 验证学生信息是否合法
     *
     * @param student 学生实体
     * @return 是否合法
     */
    public static boolean isStudentValid(Student student) {
        // 验证学生实体是否为空
        if (student == null) {
            return false;
        }
        // 验证学生信息是否为空
        if (student.getName() == null ||
                student.getSex() == null ||
                student.getProvince() == null ||
                student.getBirthday() == null ||
                student.getHeight() == null ||
                student.getEducation() == null) {
            return false;
        }
        // 验证学生信息是否合法
        return !student.getName().isEmpty() &&
                EnumUtils.isIncludeCode(Sex.class, student.getSex()) &&
                EnumUtils.isIncludeCode(Province.class, student.getProvince()) &&
                student.getBirthday().before(Date.valueOf(LocalDate.now())) &&
                student.getHeight() >= 0 &&
                EnumUtils.isIncludeCode(Education.class, student.getEducation());
    }

    /**
     * 验证已填学生信息是否合法
     *
     * @param student 学生实体
     * @return 是否合法
     */
    public static boolean isStudentValidFilled(Student student) {
        // 验证学生实体是否为空
        if (student == null) {
            return false;
        }
        // 验证学生信息是否合法
        return (student.getId() == null || student.getId() > 0) &&
                (student.getName() == null || !student.getName().isEmpty()) &&
                (student.getSex() == null || EnumUtils.isIncludeCode(Sex.class, student.getSex())) &&
                (student.getProvince() == null || EnumUtils.isIncludeCode(Province.class, student.getProvince())) &&
                (student.getBirthday() == null || student.getBirthday().before(Date.valueOf(LocalDate.now()))) &&
                (student.getHeight() == null || student.getHeight() > 0) &&
                (student.getEducation() == null || EnumUtils.isIncludeCode(Education.class, student.getEducation()));
    }
}
